<?php
class ProductAction extends Action{
   public function _initialize(){//初始化
		R("Home.Public","top");
		R("Home.Public","bottom");
   }
   public function index(){
	  import("ORG.Com.DiyCache");
	  $mycache = new DiyCache;
	  if(!$mycache->is_cached()){//处理自定义缓存
	     /*安全处理*/
		 checkget();
		 checkpost();
		 $typeid  = $_GET['typeid']?$_GET['typeid']:101;
		 if(empty($typeid)||!is_numeric($typeid))alert('参数错误');
		 $this->assign("typeid",$typeid);
		 
		 $id = $_GET['id'];
		 
		 $this->assign("id",$id);
		 
		 /*安全处理*/
		 //求出分类
		 $col_id = 133;
		 $sysclass = M("sysclass");
		 $type_list = $sysclass->where("col_id = $col_id")->field("class_name,id")->order("sequence desc")->findAll();
		 $this->assign("type_list",$type_list);
		 //求出数据
		 
		 $product = M("product");
		 $count = $product->where("typeid=$typeid")->count();
		 $pagesize = 4;
		 Vendor("LJW.Page");
		 $mypage = new Page($count,$pagesize,3,U("Product/index/typeid/$typeid"));
		 $pr_list = $product->where("typeid=$typeid")->limit($mypage->start.",".$mypage->pagesize)->order("sequence desc")->findAll();
		 $this->assign("pr_list",$pr_list);
		 
		 /*分页处理开始*/
		 $this->assign("mypage",$mypage);
		 $f_url=$mypage->url."/p/1";//首页
		 $e_url=$mypage->url."/p/".$mypage->pagenum;//尾页
             
		 $p_url=$mypage->url."/p/".(($mypage->absolutepage-1<=0)?1:($mypage->absolutepage-1));//上一页
		 $n_url=$mypage->url."/p/".(($mypage->absolutepage+1>$mypage->pagenum)?$mypage->pagenum:($mypage->absolutepage+1));//下一页
		 
		 $web_public_path = WEB_PUBLIC_PATH;
		 
		 
		 $div_str = <<<EOT
		 <ul><li><a href="{$f_url}"><img src="{$web_public_path}/images/home/prolist_22.gif" /></a></li><li><a href="{$p_url}"><img src="{$web_public_path}/images/home/prolist_24.gif" /></a></li>
EOT;
        for($i=1;$i<=$mypage->pagenum;$i++){
			    $u=$mypage->url."/p/$i";
			    $div_str.="<li><a href='$u'>$i</a></li>";
		}
		$div_str.=<<<EOT
		<li><a href="{$n_url}"><img src="{$web_public_path}/images/home/prolist_27.gif" /></a></li><li><a href="{$e_url}"><img src="{$web_public_path}/images/home/prolist_29.gif" /></a></li></ul>
EOT;
		 $this->assign("divpage",$div_str);
		  /*分页处理结束*/
		 
		 if(empty($id)){
			 $this->assign("pr_info",$pr_list[0]); 
		 }else{
			 $this->assign("pr_info",$product->where("id=$id")->find());
		 }
		 
		if(C("diy_cache"))$mycache->create_cache($this->fetch());//创建缓存 
	    $this->display();
	  }
   }
}
?>